package com.tjbank.cssys.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CreditDerate;
import com.tjbank.cssys.repository.CreditDerateMapper;
import com.tjbank.cssys.web.service.CreditDerateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;


@Service
public class CreditDerateServiceImpl implements CreditDerateService {

    private static final Logger logger = LoggerFactory.getLogger(CreditDerateServiceImpl.class);

    @Autowired
    private CreditDerateMapper creditDerateMapper;
    /*获取 详情*/
    @Override
    public Map getDetailsBybatchNumber(Map<String, String> map) {
        Map<Object,Object> resultMap=new HashMap<>();
        List<CreditDerate> detailsBybatchNumber = creditDerateMapper.getDetailsBybatchNumber(map);
        resultMap.put("map",detailsBybatchNumber);
        return  resultMap;
    }

    @Override
    public CreditDerate selectByPrimaryKey(Long id) {
        return creditDerateMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<CreditDerate> selectList(CreditDerate creditDerate, Integer pageNum, Integer pageSize , HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
        List<CreditDerate> creditDerates = creditDerateMapper.selectList(creditDerate);

        PageInfo<CreditDerate> creditDeratePageInfo = new PageInfo<CreditDerate>(creditDerates);
        return creditDeratePageInfo;
    }

    @Override
    public int UpdateAudit(CreditDerate creditDerate) {

        creditDerate.setCaseStatue(1);

        return creditDerateMapper.UpdateAudit(creditDerate);
    }

    @Override
    public int UpdateAccountStatus(CreditDerate creditDerate) {
        logger.info("状态设置为0无效");
        creditDerate.setAccountStatus(0);
        return creditDerateMapper.UpdateAccountStatus(creditDerate);
    }


    @Override
    public int deleteByPrimaryKey(Long id) {
        return creditDerateMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(CreditDerate record) {
        //逻辑  删除状态1未删除  0已删除
        record.setAccountStatus(1);
        //设置 信用卡 状态默认   0未审批状态
        record.setCaseStatue(0);
        return creditDerateMapper.insert(record);
    }
}
